#include "compresssendthread.h"
#include <QDebug>


CompressSendThread::CompressSendThread(QObject *parent)
    : QThread(parent)
    , m_bStart(true)
{

}

void CompressSendThread::run()
{
    while (m_bStart) {//用来停止

        CompressSend *task = popTask();
        if(task){
            if(task->compressSendImg()){
                emit CompressPictureOver();
                delete task;//用完删除
                task = nullptr;
            }
        }else{
            delete task;
        }
        QThread::msleep(50);
    }
}

void CompressSendThread::addTask(CompressSend *task)
{
    m_mutex.lock();
    m_taskList.push_front(task);
    m_mutex.unlock();
}

CompressSend *CompressSendThread::popTask()
{
    m_mutex.lock();
    CompressSend *task;
    if(0 == m_taskList.size())
    {
        task = nullptr;
    }
    else
    {
        task = m_taskList.takeFirst();
    }
    m_mutex.unlock();
    return task;
}
